<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <link rel="shortcut icon" href="/assets/img/favicon.ico"/>
    <!-- Loading Bootstrap -->
    <link href="/assets/css/backend.min.css" rel="stylesheet">
    <script src="/assets/js/layer/jquery-3.1.1.min.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=E4a5jsic8O8ZbGplbg6wMHmLdMzk1gHV"></script>
    <style type="text/css">
        #allmap {
            width: 900px;
            height: 450px;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
</head>

<body class="inside-header inside-aside is-dialog">
<div id="main" role="main">
    <div class="tab-content tab-addtabs">
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <section class="content-header hide">
                        <h1>
                            控制台
                            <small>Control panel</small>
                        </h1>
                    </section>
                    <div class="content">
                        <form id="edit-form" class="form-horizontal form-ajax" role="form" data-toggle="validator"
                              method="POST" action="{:url('add')}">

                            <div class="form-group">
                                <label for="c-category_id" class="control-label col-xs-12 col-sm-2">模板名称:</label>

                                <div class="col-xs-12 col-sm-8">
                                    <input id="c-category_id" class="form-control selectpage"
                                           data-source="category/selectpage" data-params='{"custom[type]":"page"}'
                                           name="title" type="text" value="" data-rule="required">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="c-type" class="control-label col-xs-12 col-sm-2">所属工地:</label>

                                <div class="col-xs-12 col-sm-8">

                                    <select id="c-type" data-rule="required" class="form-control selectpicker"
                                            name="building_id">
                                        {volist name="building_list" id="vo"}
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/volist}
                                    </select>

                                </div>
                            </div>


                            <div class="form-group">
                                <label for="c-status" class="control-label col-xs-12 col-sm-2">规划路线:</label>

                                <div class="col-xs-12 col-sm-8">
                                    <div id="allmap"></div>
                                </div>

                            </div>


                            <div class="form-group">
                                <label for="c-status" class="control-label col-xs-12 col-sm-2">状态:</label>

                                <div class="col-xs-12 col-sm-8">
                                    <label for="row[status]-normal"><input id="row[status]-normal" checked="checked"
                                                                           name="status" type="radio" value="1">
                                        正常</label>
                                    <label for="row[status]-hidden"><input id="row[status]-hidden" name="status"
                                                                           type="radio" value="0"> 隐藏</label></div>
                            </div>
                            <div class="form-group ">
                                <label class="control-label col-xs-12 col-sm-2"></label>

                                <div class="col-xs-12 col-sm-8">
                                    <button type="submit" class="btn btn-success btn-embossed ">确定</button>
                                    <button type="reset" class="btn btn-default btn-embossed">重置</button>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 12);

    var transit = new BMap.DrivingRoute(map, {
        renderOptions: {
            map: map,
            autoViewport: true,
            enableDragging: true //起终点可进行拖拽
        }
        ,
        onPolylinesSet: function (routes) {
            var pStart = (routes[0].Nr)[0].Uh;//起点
            var pEnd;//终点
            var wArr = [];//途径点
            var rLen = routes.length;
            if (rLen > 1) {
                for (var i = 0, len = rLen - 1; i < len; i++) {
                    var pp = routes[i].Nr.pop().Uh;
                    wArr.push(pp);
                }
            }
            pEnd = routes[rLen - 1].Nr.pop().Uh;//获取终点


            console.log(JSON.stringify(pStart));
            console.log(JSON.stringify(pEnd));
            console.log(JSON.stringify(wArr));

            sessionStorage.setItem("pStart", JSON.stringify(pStart));
            sessionStorage.setItem("pEnd", JSON.stringify(pEnd));
            sessionStorage.setItem("wArr", JSON.stringify(wArr));

        }
    });
    //            transit.search("西单", "魏公村");

    var p1 = new BMap.Point(116.301934, 39.977444);//起始点坐标
    var p2 = new BMap.Point(116.508328, 39.919141);//终点坐标
    var w = [new BMap.Point(116.458742, 39.943514)];//途经点


    if (sessionStorage.getItem("pStart")) {
        var p1Obj = JSON.parse(sessionStorage.getItem("pStart"));
        var p1Tem = new BMap.Point(p1Obj.lng, p1Obj.lat);
//        console.log(p1Tem);
        p1 = p1Tem;
    }
    if (sessionStorage.getItem("pEnd")) {
        var p2Obj = JSON.parse(sessionStorage.getItem("pEnd"));
        var p2Tem = new BMap.Point(p2Obj.lng, p2Obj.lat);
//        console.log(p2Tem);
        p2 = p2Tem;
    }
    if (sessionStorage.getItem("wArr")) {
        var wObjArr = JSON.parse(sessionStorage.getItem("wArr"));
        var wTem = [];
        for (var i = 0, len = wObjArr.length; i < len; i++) {
            wTem.push(new BMap.Point(wObjArr[i].lng, wObjArr[i].lat));
        }
//        console.log(wTem);
        w = wTem;
    }

    transit.search(p1, p2, {waypoints: w});

</script>
</body>
</html>